package ic.symbols;

import ic.ast.decl.DeclMethod;
import ic.types.MethodType;
import ic.types.TypeTable;

/**
 * Created with IntelliJ IDEA.
 * User: Matan
 * Date: 12/10/13
 * Time: 11:28 AM
 */
public class MethodSymbol extends Symbol {

    private MethodType methodType;
    private boolean isStatic;

    public MethodSymbol(DeclMethod declMethod) throws Exception {
        this(declMethod, declMethod.isStatic());
    }

    public MethodSymbol(DeclMethod declMethod, boolean isStatic) throws Exception {
        super(declMethod.getName(), SymbolType.METHOD, declMethod.getLine());
        this.methodType = TypeTable.getType(declMethod);
        this.isStatic = isStatic;
    }

    public MethodType getMethodType() {
        return this.methodType;
    }

    public boolean isStatic() {
        return this.isStatic;
    }

    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append(isStatic() ? "Static" : "Virtual");
        str.append(" method:  ");
        str.append(getID());
        str.append(" : ");
        str.append(getMethodType());
        return str.toString();
    }
}

